Explore Map
Contents
Explore Map#
Import Libraries#
External Libraries#
import geopandas as gpd
External Libraries#
Define Variables#
nyc_street_flooding_input = 'data/street-flooding/clean_street-flood-complaints_rows-all.geojson'
Get Clean Data#
street_flooding_gdf = gpd.read_file(nyc_street_flooding_input)
Unexpected exception formatting exception. Falling back to standard exception
Traceback (most recent call last):
File "fiona\ogrext.pyx", line 136, in fiona.ogrext.gdal_open_vector
File "fiona\_err.pyx", line 291, in fiona._err.exc_wrap_pointer
fiona._err.CPLE_OpenFailedError: Failed to read GeoJSON data
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\datal\anaconda3\envs\nyc-street-flooding-analysis\Lib\site-packages\IPython\core\interactiveshell.py", line 3460, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "C:\Users\datal\AppData\Local\Temp\ipykernel_27876\367817511.py", line 1, in <module>
street_flooding_gdf = gpd.read_file(nyc_street_flooding_input)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\datal\anaconda3\envs\nyc-street-flooding-analysis\Lib\site-packages\geopandas\io\file.py", line 259, in _read_file
return _read_file_fiona(
^^^^^^^^^^^^^^^^^
File "C:\Users\datal\anaconda3\envs\nyc-street-flooding-analysis\Lib\site-packages\geopandas\io\file.py", line 303, in _read_file_fiona
with reader(path_or_bytes, **kwargs) as features:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\datal\anaconda3\envs\nyc-street-flooding-analysis\Lib\site-packages\fiona\env.py", line 457, in wrapper
return f(*args, **kwds)
^^^^^^^^^^^^^^^^
File "C:\Users\datal\anaconda3\envs\nyc-street-flooding-analysis\Lib\site-packages\fiona\__init__.py", line 335, in open
colxn = Collection(
^^^^^^^^^^^
File "C:\Users\datal\anaconda3\envs\nyc-street-flooding-analysis\Lib\site-packages\fiona\collection.py", line 234, in __init__
self.session.start(self, **kwargs)
File "fiona\ogrext.pyx", line 587, in fiona.ogrext.Session.start
File "fiona\ogrext.pyx", line 143, in fiona.ogrext.gdal_open_vector
fiona.errors.DriverError: Failed to read GeoJSON data
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\datal\anaconda3\envs\nyc-street-flooding-analysis\Lib\site-packages\IPython\core\interactiveshell.py", line 2057, in showtraceback
stb = self.InteractiveTB.structured_traceback(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\datal\anaconda3\envs\nyc-street-flooding-analysis\Lib\site-packages\IPython\core\ultratb.py", line 1288, in structured_traceback
return FormattedTB.structured_traceback(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\datal\anaconda3\envs\nyc-street-flooding-analysis\Lib\site-packages\IPython\core\ultratb.py", line 1177, in structured_traceback
return VerboseTB.structured_traceback(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\datal\anaconda3\envs\nyc-street-flooding-analysis\Lib\site-packages\IPython\core\ultratb.py", line 1049, in structured_traceback
formatted_exceptions += self.format_exception_as_a_whole(etype, evalue, etb, lines_of_context,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\datal\anaconda3\envs\nyc-street-flooding-analysis\Lib\site-packages\IPython\core\ultratb.py", line 935, in format_exception_as_a_whole
self.get_records(etb, number_of_lines_of_context, tb_offset) if etb else []
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\datal\anaconda3\envs\nyc-street-flooding-analysis\Lib\site-packages\IPython\core\ultratb.py", line 1003, in get_records
lines, first = inspect.getsourcelines(etb.tb_frame)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\datal\anaconda3\envs\nyc-street-flooding-analysis\Lib\inspect.py", line 1252, in getsourcelines
lines, lnum = findsource(object)
^^^^^^^^^^^^^^^^^^
File "C:\Users\datal\anaconda3\envs\nyc-street-flooding-analysis\Lib\inspect.py", line 1081, in findsource
raise OSError('could not get source code')
OSError: could not get source code
View Complaints on OpenStreetMap#
street_flooding_gdf['geometry'] = street_flooding_gdf.geometry
popup_columns = [
'geometry',
'created_date',
'incident_address',
'city',
'incident_zip',
'borough',
'bbl',
'status',
]
Convert datetime64 data type to string#
datetime64 needs to be converted to string before viewing using
GeoPandas.explore(), otherwise the following error will appear:
Object of type Timestamp is not JSON serializable
# created_date, resolution_action_updated_date, closed_date
street_flooding_gdf['created_date'] = street_flooding_gdf['created_date'].dt.strftime('%Y-%m-%d %H:%M:%S')
street_flooding_gdf['resolution_action_updated_date'] = street_flooding_gdf['resolution_action_updated_date'].dt.strftime('%Y-%m-%d %H:%M:%S')
street_flooding_gdf['closed_date'] = street_flooding_gdf['closed_date'].dt.strftime('%Y-%m-%d %H:%M:%S')
street_flooding_gdf[popup_columns].explore('borough')
Make this Notebook Trusted to load map: File -> Trust Notebook